﻿using Consulta.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using WebMatrix.WebData;
using TrabajoFinal.Models;

namespace Consulta.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Home/
        ContextoDatos db = new ContextoDatos();

        [Authorize(Roles="Admin, Client")]
        public ActionResult Index()
        {
            ViewBag.roles = Roles.GetRolesForUser();
            ViewBag.nombreUser = WebSecurity.CurrentUserName;
            return View();
        }

        public ActionResult Login()
        {
            return View();
        }

        [Authorize(Roles="Admin, Client")]
        public ActionResult Logout()
        {
            WebSecurity.Logout();
            return RedirectToAction("Index");
        }

        public ActionResult Logginator(LoginClass loginData)
        {
            if (WebSecurity.Login(loginData.user, loginData.pass, loginData.check))
            {            
                return RedirectToAction("Index");
            }
            else
            {
                ViewBag.mensaje = "Usuario o Constraseña Incorrecto";
                return View("Login");
            }
        }
    }
}
